<?php

include_once $app."dao/dao_usuario.php";

$dao_usuario = new dao_usuario();
$model_usuario = $dao_usuario->select($_SESSION["USU_ID"]);

?>

<script>

$(document).ready(function(){
    desabilitaBotao($("input:submit",document.forms));
    $("input", document.forms[0]).prop("disabled", true);
    $("input", document.forms[1]).prop("disabled", true);
});

//$("#img_cliente").ready(function(){
//    $("#img_cliente").attr("src", "./imagens/clientes/<?php //echo $_SESSION["CLI_ID"] ?>.jpg?"+(new Date()).getTime());
//});

function valida(){
        form = document.usuario;
        senha = form.elements["usuario[USU_SENHA]"];
        senha_verificacao = form.elements["senha_verificacao"];
        
        if (senha.value.length < 6){
            alert("A senha deve ter no mínimo 6 caracteres");
            return false;
        }else if (senha.value != senha_verificacao.value){
            alert("As senhas não coincidem");
            return false;
        }
        show_loading_screen();
        return true;
}

function configura_form(component){
    desabilitaBotao($("input:submit",document.forms));
    $("input", document.forms).prop("disabled", true);
    $("select", document.forms[2]).prop("disabled", true);
    switch (component) {
            case document.getElementsByName("action")[0]:
                $("input", document.forms[0]).prop("disabled", false);
                habilitaBotao($("input:submit", document.forms[0]));
                break;
            case document.getElementsByName("action")[1]:
                $("input", document.forms[1]).prop("disabled", false);
                habilitaBotao($("input:submit", document.forms[1]));
                break;
            default:
                break;
        }

}

</script>
    
<span class="titulo_conteudo">Altera&ccedil;&otilde;s do Usu&aacute;rio '<?php echo $model_usuario->getUSU_NOME() ?>'</span>
<div class="corpo_conteudo">
    <fieldset>
        <legend><input type="radio" name="action" onchange="configura_form(this);"/><span>Alterar Senha</span></legend>
        <form class="formularios" id="form_usuario" name="usuario" action="./action.php?action=usuario_altera_senha" onsubmit="return valida();" method="post">
        <br/>
        <input type="hidden" name="usuario[USU_ID]" value='<?php echo $model_usuario->USU_ID ?>'/>
        <table>
            <tr><td>Usu&aacute;rio:*</td><td><input type="text" name="nome" readonly="readonly" value='<?php echo $model_usuario->USU_NOME ?>'/></td></tr>
            <tr><td>Senha:*</td><td><input type="password" name="usuario[USU_SENHA]" maxlength="30"/></td></tr>
            <tr><td>Repetir Senha:</td><td><input type="password" name="senha_verificacao" maxlength="30"/></td></tr>    
        </table>
        <small>* A senha do usu&aacute;rio deve ter no m&iacute;nimo 6 e no m&aacute;ximo 30 caracteres</small><br/><br/>
        <br/>
        <input type="submit" value="Salvar"/>
        </form>
    </fieldset>
</div>
<div class="corpo_conteudo">
    <fieldset>
        <legend><input type="radio" name="action" onchange="configura_form(this);"/><span>Mudar Logomarca</span></legend>
        <table>
            <tr><td>
                    <form class="formularios" id="form_usuario" name="logo" enctype="multipart/form-data" action="./action.php?action=usuario_altera_logo" method="post" onsubmit="show_loading_screen();">
                        <br/>
                        <input type="hidden" name="CLI_ID" value="<?php echo $_SESSION["CLI_ID"] ?>" />
                        <input type="hidden" name="MAX_FILE_SIZE" value="4194304" />
                        Arquivo:<br/>
                        <input type="file" name="arquivo"/><br/>
                        <small>Tamanho ideal da imagem &eacute; de 100x75 pixels</small><br/><br/><br/>
                        <input type="submit" value="Salvar"/>
                    </form>
                </td>
                <td>
                    <img style="border: 1px solid #ccc" src="imagens/clientes/cliente_100x75.php?id=<?php echo $_SESSION["CLI_ID"] ?>" id="img_cliente" width="100" height="75" alt="LOGO"/>
                </td>
            </tr>
        </table>
    </fieldset>
</div>